package com.sc.nft.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.HnaC2cTransferDto;
import com.sc.nft.helper.HnaPayHelper;
import com.sc.nft.sup.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/hna/pay")
public class HnaPayController {
  private final HnaPayHelper hnaPayHelper;

  @PostMapping("/c2c")
  @SysMemberLogin
  public Result<JSONObject> c2cTransfer(@RequestBody @Valid HnaC2cTransferDto dto) {
    if (dto.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
      throw new RuntimeException("转款金额需大于0");
    }
    return Result.success(
        hnaPayHelper.c2cTransfer(dto.getFrom(), dto.getTo(), dto.getAmount().toPlainString()));
  }
}
